import ScreenPositionUtil from "./ScreenPositionUtil";
import GameConfig from "./GameConfig";
import DrawUtil from "./DrawUtil";

var countImg = 0;
/**
 * 网格区域
 */
export default class ContentText extends Laya.Sprite {
    constructor() {
        super();

        this.contentTextData = null;
        this.contentAreaData = null;
        this.tag = "";
        this.parentAreaView = null;

        this.contentTextView = new Laya.Text;
        this.addChild(this.contentTextView)
        this.contentTextView.pos(0, 0);

        this.contentTextView.align = "center";
        this.contentTextView.valign = "middle";
        this.contentTextView.font = "Microsoft YaHei";
        this.contentTextView.color = "#bb9367";
    }

    /**
     * 文字区域加入文字
     * @param {*} inAreaData 文字区域数据
     * @param {*} inStrs 文字数据 1行 2行
     * @param {*} inParentAreaView 父组件
     */
    initByContentTextData(inAreaData, inStrs, inParentAreaView) {
        this.contentAreaData = inAreaData;
        this.parentAreaView = inParentAreaView;
        this.contentTextView.overflow = Laya.Text.HIDDEN;
        this.contentTextView.size(this.contentAreaData.areaWidth * GameConfig.GridWidth,
            this.contentAreaData.isTipFirstLine == 0 ? this.contentAreaData.areaHeight * GameConfig.GridWidth : GameConfig.GridWidth);
        
        this.contentTextView.fontSize = GameConfig.GridWidth * 0.225;
        this.contentTextView.leading = GameConfig.GridWidth * 0.15;

        this.x = GameConfig.GridWidth * inAreaData.textPadding[0];
        this.y = GameConfig.GridWidth * inAreaData.textPadding[1];
        this.contentTextView.width = this.contentTextView.width - GameConfig.GridWidth * (inAreaData.textPadding[0] + inAreaData.textPadding[2]);
        // this.height = this.height - this.y - GameConfig.GridWidth * inAreaData.textPadding[3];
        this.updateTextContent(inStrs)
    }

    updateTextContent(inTextData) {
        this.contentTextData = inTextData;

        let strs = "";
        for(let i = 0 ; i < this.contentTextData.length; i++) {
            strs += i != 0 ? "\n" : "";
            strs += this.contentTextData[i];
        }
        this.contentTextView.text = strs;

        if(this.contentTextData.length > 1) {
            this.contentTextView.y = GameConfig.GridWidth * 0.1;
        }
        else {
            this.contentTextView.y = GameConfig.GridWidth * 0.;
        }
    }

    setBoundsAndBtnsVisible() {
        
    }
}